#ifndef __ENP_CLIENT_H__
#define __ENP_CLIENT_H__

#include "enpdef.h"

class CEnpCtrl;
class CEnpListen;
class CEnpClient: public CTEpollObject<CEnpCtrl>
{
protected:
    friend class CEnpCtrl;
    friend class CEnpClientFactory;

    CEnpCtrl*           m_pstOwner;
    CEnpListen*         m_pstListern;
    CTSocket    		m_stSocket;
    CEnpNetHead         m_stNetHead;
    CTBuffer			m_stRecvBuf;			///< 接收缓冲区
    CTBuffer			m_stSendBuf;			///< 发送缓冲区
    int                 m_iRecvBytes;           ///< 接收的累计数据量
    int                 m_iSendBytes;           ///< 发送的累计数据量
	unsigned int		m_uiSeq;				///< 客户端序号，每个客户端连接分配一个
    int                 m_iShmQueueIndex;       ///< 共享内存队列下标

public:
    CEnpClient():
        m_stSocket(PF_INET, SOCK_STREAM, false),
        m_iRecvBytes(0),
        m_iSendBytes(0),
        m_iShmQueueIndex(0)
    {
    }

    virtual ~CEnpClient()
    {
        Unregister(); // 先Unregister从epoll注销, 然后再关闭socket
    }

    void SetShmQueueIndex(int iVal) {m_iShmQueueIndex = iVal;}

    int Init(CEnpCtrl& stOwner, CEnpListen& stListen,
        SOCKET iSocket, unsigned int uiIP, unsigned short ushPort);

};

#endif //__ENP_CLIENT_H__
